﻿@using LeadMaster.Models

@model IEnumerable<LeadMaster.Models.Enquiries>

<style type="text/css">
    .TableCell
    {
        font-family: Arial, Helvetica, sans-serif; 
        font-size: 11px; 
        color: #808080;
    }
</style>
<div style="float:right;">
    <img src="~/Images/phone_icon.png" class="registerenquiry" data-leadid="@(@Model.FirstOrDefault().LeadID)" 
    style="width: 35px; height: 35px; cursor: pointer; vertical-align: middle;" alt="Enquiries" />
</div>

<table class="listtable contactstable" cellspacing="0" cellpadding="0" style="width: 100%;" id="enquirylist">
    <tr>
        <th class="tableheader">
            @Html.Label("Contact Name")
        </th>
        <th class="tableheader">
            @Html.Label("Enquiry Date")
        </th>
        <th class="tableheader">
            @Html.Label("Source")
        </th>
        <th class="tableheader">
            @Html.Label("Notes")
        </th>
    </tr>
@{
bool firstrowflag=true;
foreach (var item in Model) {
    <tr @if (firstrowflag)
	{
		 @:id="firstrow"
         firstrowflag = false;
	}>
        <td class="TableCell">
            @(item.Contact.Forename) @(item.Contact.Surname)
        </td>
        <td class="TableCell">
            @item.EnquiryDate.ToShortDateString() @item.EnquiryDate.ToShortTimeString()
            @item.User.UserName
        </td>
        <td class="TableCell">
        @switch (item.EnquirySource)
        {
            case "T" :
                @:Telephone
                break;                                          
            case "E" :
                @:Email
                break;
            case "M" :
                @:Meeting
                break;
            case "F" :
                @:Fax
                break;
            default:
            break;
        }
        </td>
        <td class="TableCell">
        @Html.TextAreaFor(modelItem => item.Notes, new { @class = "commsnotes readonlytextarea", @readonly = "true" })
        </td>
    </tr>
}
}

</table>


<div id="createenquirydialog" class="overlay">
</div>

<script type="text/javascript">
    $(document).ready(function () {

        $("#createenquirydialog").dialog(
        {
            autoOpen: false,
            width: 900,
            open: function () { $(".ui-dialog").css("box-shadow", "#000 5px 5px 5px"); },
            position: { my: 'center', at: 'center', of: window },
            modal: true,
            draggable: false,
            dialogClass: 'notitle',
            buttons: {
                cancel: function () {
                    $(this).dialog("close");
                }
            }
        });

        $(".registerenquiry").click(function () {
            $("#hdnNote").val("true");
            var id = $(this).data("leadid");
            $("#createenquirydialog").dialog("open");
            $("#createenquirydialog").html('<div style="text-align: center;"><div><img src="@Url.Content("~/Images/ajaxspinner_large.gif")" alt="Loading..." style="margin: 20px;" /></div><div>Loading...</div></div>');
            $('#createenquirydialog').load('@(Url.Action("Create", "Enquiry"))/' + id);
        });

    });
</script>
